package com.ruoyi.project.system.service.impl;

import com.ruoyi.project.system.domain.CollegeStaff;
import com.ruoyi.project.system.domain.Member;
import com.ruoyi.project.system.domain.Student;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.*;
import com.ruoyi.project.system.service.IWxLoginService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.List;


@Service
public class WxLoginServiceImpl implements IWxLoginService {

    @Autowired
    private StudentMapper studentMapper;


    @Autowired
    private MemberMapper memberMapper;


    @Autowired
    private CollegeStaffMapper collegeStaffMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Transient
    @Override
    public SysUser studentLogin(String idCord, String name,Integer memberId) {
        studentMapper.updateMemberIdByIdCard(idCord,memberId);
        return studentMapper.getUserByIdCardName(idCord,name);
    }

    @Override
    public SysUser teacherLogin(String user, String pwd) {
        Member member = new Member();
        member.setPwd(pwd);
        member.setCode(user);
        List<Member> memberList = memberMapper.selectMemberList(member);
        if(memberList.size()==0){
            //抛出异常
        }else{

            CollegeStaff staff = collegeStaffMapper.selectCollegeByMeberId(memberList.get(memberList.size() - 1).getId());

            return sysUserMapper.selectUserById(staff.getUserId().longValue());
        }
        return null;
    }
}
